﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using SmartSpace.Core;

namespace SmartSpace.Cwt
{
    public class CwtContext : DomainContext
    {
        public CwtContext(DbContext dbContext)
            : base(dbContext)
        {
        }

        public static void Build(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Category>().ToTable("CWT_Category");
            modelBuilder.Entity<Category>().HasKey(p => p.Id);

            modelBuilder.Entity<Article>().ToTable("CWT_Article");
            modelBuilder.Entity<Article>().HasKey(p => p.Id);
            modelBuilder.Entity<Article>().HasRequired(p => p.Category)
                .WithMany(p => p.Articles).HasForeignKey(p => p.CategoryId);

            modelBuilder.Entity<Company>().ToTable("CWT_Company");
            modelBuilder.Entity<Company>().HasKey(p => p.Id);

            modelBuilder.Entity<Summary>().ToTable("CWT_Summary");
            modelBuilder.Entity<Summary>().HasKey(p => p.Id);

            modelBuilder.Entity<Contact>().ToTable("CWT_Contact");
            modelBuilder.Entity<Contact>().HasKey(p => p.Id);

            modelBuilder.Entity<PartnerLink>().ToTable("CWT_PartnerLink");
            modelBuilder.Entity<PartnerLink>().HasKey(p => p.Id);
        }
    }
}
